package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.activity.AuthorsActivity;
import com.zzk.lanouhn.myapplication1.modles.CollectSingleGood;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * 最近喜欢适配器
 * Created by lanouhn on 16/9/18.
 */
public class NewestLikeAdapter extends RecyclerView.Adapter<NewestLikeAdapter.newestlikeHolder>{

    private Context context;
    private List<CollectSingleGood.DataBean.LikesListBean> userList=new ArrayList<>();

    public NewestLikeAdapter(Context context, List<CollectSingleGood.DataBean.LikesListBean> userList) {
        this.context = context;
        this.userList = userList;
    }

    @Override
    public newestlikeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_newestlike,null);
        newestlikeHolder holder=new newestlikeHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(newestlikeHolder holder, final int position) {
        Picasso.with(context).load(userList.get(position).getAvatar()).into(holder.iv_icon);
        holder.tv_name.setText(userList.get(position).getNickname());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, AuthorsActivity.class);
                Bundle bundle=new Bundle();
                bundle.putString("authorId",userList.get(position).getUser_id());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return userList.size();
    }

    public class newestlikeHolder extends RecyclerView.ViewHolder{
        private ImageView iv_icon;
        private TextView tv_name;
        public newestlikeHolder(View itemView) {
            super(itemView);
            iv_icon= (ImageView) itemView.findViewById(R.id.iv_icon_user_newest);
            tv_name= (TextView) itemView.findViewById(R.id.tv_name_user_newest);
        }
    }
}
